package org.grey.edz.rule.parser;

import bsh.Interpreter;
import org.grey.edz.IDZipperProcessor;
import org.grey.edz.ex.EDZException;
import org.grey.edz.payload.EDZPayload;
import org.grey.edz.rule.EDZRule;
import org.grey.edz.rule.parser.i.IDZipRuleParser;
import org.grey.edz.util.EDZAssert;
import org.grey.edz.util.EDZReflectUtil;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;

/**
 * @program: easy-data-zipper
 * @ClassName DefRuleParser
 * @description:
 * @author: Grey
 * @create: 2024-02-20 14:02
 */
public class DefRuleParser implements IDZipRuleParser {


    @Override
    public boolean predicate(IDZipperProcessor processor) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        EDZPayload payload = null;
        if(processor instanceof EDZPayload){
            payload = (EDZPayload) processor;
        }

        EDZAssert.throwWhenTrue(null == payload, new EDZException("断言异常:非搭配负载的EDZ处理器"));

        Object source = payload.getSource();
        String[] toolProperties = payload.getToolProperties();
        Class<?> clazz = payload.getClazz();
        for (String toolProperty : toolProperties) {
            Object invoke = EDZReflectUtil.method(clazz, EDZReflectUtil.getter(toolProperty)).invoke(source);
            if(!ruleScheduling(toolProperty, invoke)){
                return false;
            }
        }
        return true;
    }

    private boolean ruleScheduling(String toolProperty , Object value){
        EDZRule rule = new EDZRule();
        Map<String, String> ruleContainer = rule.getRuleContainer();

        Interpreter inter = new Interpreter();



        return false;

    }

    //now > endDate
}
